package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintLayout.LayoutParams.PARENT_ID
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.LinearLayout.VERTICAL
import android.widget.TextView
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout

class TitleBarActivityUi(click: View.OnClickListener):AnkoComponent<Context>{
    private val clickListener=click
    lateinit var parent_view:LinearLayout
    lateinit var float_action_bu:TextView
    lateinit var base_bar_title_tv:TextView
    lateinit var base_bar_back_img:ImageView
    lateinit var base_bar_bg_clt:ConstraintLayout


    override fun createView(ui: AnkoContext<Context>): View= with(ui){
        linearLayout{
            orientation=VERTICAL

            base_bar_bg_clt=constraintLayout{
                lparams(width= matchParent,height = context.dimenAttr(R.attr.actionBarSize))
                backgroundColor=context.resources.getColor(R.color.colorsTitleBar)
                id=R.id.base_bar_bg_clt

                base_bar_back_img=imageView{
                    id=R.id.base_bar_back_img
                    setOnClickListener(clickListener)
                    background=context.getDrawable(R.mipmap.back_img)
                }.lparams(width=dip(40),height=dip(40)){
                    bottomToBottom=PARENT_ID
                    leftToLeft=PARENT_ID
                }

                base_bar_title_tv=textView {
                    text="扫码"
                    id=R.id.base_bar_title_tv
                    textSize=dip(12).toFloat()
                    gravity=Gravity.CENTER
                    textColor= Color.WHITE
                }.lparams(width=0,height = wrapContent){
                    leftToLeft= PARENT_ID
                    rightToRight= PARENT_ID
                    bottomToBottom= PARENT_ID
                    topToTop=R.id.base_bar_back_img
                }

                float_action_bu=textView{
                    text="历史记录"
                    id=R.id.float_action_bu
                    gravity=Gravity.CENTER
                    visibility=View.GONE
                    textColor= Color.WHITE
                    textSize=dip(10).toFloat()
                }.lparams(width= wrapContent,height =0){
                    setMargins(0,0,dip(8),0)
                    rightToRight= PARENT_ID
                    bottomToBottom= PARENT_ID
                    topToTop=R.id.base_bar_back_img
                }
            }

            parent_view=linearLayout{
                id=R.id.parent_view
                orientation=VERTICAL
            }.lparams(width= matchParent,height =0){
                weight= 1F
            }
        }
    }
}